<%--
  Created by IntelliJ IDEA.
  User: dj
  Date: 2018-11-02
  Time: 15:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ include file="/common/baseMeta.jsp" %>
<link rel="stylesheet" href="/static/js/layui/css/layui.css" media="all">
<script type="text/javascript" href="/static/js/layui/html5.min.js"></script>
<script type="text/javascript" href="/static/js/layui/respond.min.js"></script>

<script type="text/javascript" src="/static/js/common.js"></script>
<script type="text/javascript" src="/static/js/dlcommon.js"></script>

<html>
<head>
    <title>添加项目</title>
    <script type="text/javascript">
        var uid = "${sysStaffEntity.uid}";//唯一标识
        var lname = "${sysStaffEntity.lname}"; //登录工号
        var uname = "${sysStaffEntity.uname}"; //登录名 
        /*页面控件信息初始化*/
        $(function () {
            var PageMode = getQueryStringRegExp("PageMode");
            //初始化科室
            $.getJSON("/commapiV2", {p_dm: "sys_ks_Get"}, function (data) {
                if (data.success) {
                    $('#jcks').combobox({
                        data: data.Table,
                        valueField: 'code',
                        textField: 'name'
                    });
                    $('#jcks').combobox('select', data.Table[0].code);
                }
            }, true);
			
			
            //初始化监测菌种
            $.getJSON("/commapiV2", {p_dm: "Sys_Dictionary_Item_GetItemPym", dic_name: "病原体"}, function (data) {
                if (data.success) {
                    $('#jcjz').combobox({
                        data: data.Table,
                        valueField: 'code',
                        textField: 'name',
                        multiple: true
                    });
                }
            }, true);
            //初始化标本
            $.getJSON("/commapiV2", {p_dm: "Sys_Dictionary_Item_GetByBz", name: "环境监测标本", bz: lname}, function (data) {
                if (data.success) {
                    $('#jcbb').combobox({
                        data: data.Table,
                        valueField: 'code',
                        textField: 'name'
                    });
                }
            }, true);
            $.ajaxSetup({
                async: false
            });
            //初始化监测类型
            $.getJSON("/commapiV2", {p_dm: "HJJC_HGZPZ_GetJCLX"}, function (data) {
                if (data.success) {
                    $('#jclx').combobox({
                        data: data.Table,
                        valueField: 'dm',
                        textField: 'mc'
                    });
                    $('#jclx').combobox('select', data.Table[0].dm);
                }
            }, true);
            $.ajaxSetup({
                async: true
            });
            $.ajaxSetup({
                async: false
            });
            SetJyxm();
            $.ajaxSetup({
                async: true
            });
            $('#jclx').combobox({
                onChange: function (param) {
                    SetJyxm();
                }
            });
            if (PageMode == "Edite") {
                Edite();
            }else
			{
			Setnum();
			}
        })
		function Setnum()
		{
            var MID = getQueryStringRegExp("mid");
			//初始化序号
            $.getJSON("/commapiV2", {p_dm: "Hjjc_content_getnum",mid:MID}, function (data) {
                if (data.success) { 
                    $("#xh").numberbox('setValue', data.Table[0].xh);
                }
            }, true);
		}
        function SetJyxm() {
            //初始化检验项目
            $.getJSON("/commapiV2", {
                p_dm: "HJJC_HGZPZ_GetJCXM",
                JCXM: $('#jclx').combobox('getValue')
            }, function (data) {
                if (data.success) {
                    $('#jyxm').combobox({
                        data: data.Table,
                        valueField: 'dm',
                        textField: 'mc'
                    });
                    $('#jyxm').combobox('select', data.Table[0].dm);
                }
            }, true);
        }
        /*数据保存*/
        function SaveData() {
            if ($('#jcks').combobox('getValue') == '') {
                alert('监测科室不能为空！');
                return;
            }
            if ($('#jclx').combobox('getValue') == '') {
                alert('监测类型不能为空！');
                return;
            }
            if ($('#jyxm').combobox('getValue') == '') {
                alert('检验项目不能为空');
                return;
            }
            if ($('#jcbb').combobox('getText') == '') {
                alert('标本不能为空');
                return;
            }
			
			
			
            var id = getQueryStringRegExp("id");
            var MID = getQueryStringRegExp("mid");
            var PageMode = getQueryStringRegExp("PageMode");
			$.ajaxSetup({
                async: false
            });
			//判断标本是否重复
            $.getJSON("/commapiV2", {
                p_dm: "Hjjc_content_get",
                mid: MID
            }, function (data) {
                if (data.success) {
                   var a= data.Table;
				    $(data.Table).each(function (index, row) {
						if(row.jcbb==$('#jcbb').combobox('getText')) {
							alert('请注意，标本填写重复');
							return;
						} 
                    });
                }
            }, true);
			$.ajaxSetup({
                async: true
            });
            var postdata = {
                Hjjc_content: {
                    JCKS: $('#jcks').combobox('getValue'),
                    JYXM: $('#jyxm').combobox('getValue'),
                    JCLX: $('#jclx').combobox('getValue'),
                    MID: MID,
                    JCJZ: $('#jcjz').combobox('getText'),
                    MD: $('#jcmd').combobox('getValue'),
                    BZ: $('#bz').textbox('getValue'),
                    JCBB: $('#jcbb').combobox('getValue'),
                    XH: $('#xh').numberbox('getValue'),
                    ID: PageMode == "Edite" ? id : $.random.getGuid()
                }
            }
            //添加环境监测标本
            $.getJSON("/commapiV2", {
                p_dm: "Sys_Dictionary_Item_AddHjjcBB",
                item_code: $('#jcbb').combobox('getText'),
                dic_name: $('#jcbb').combobox('getText'),
                userid: lname
            }, function (data) {
                if (data.success) {
                }
            }, true);
            dLong.postajax("/commapiV2?p_dm=Hjjc_content_Add", postdata, function (data) {
                layer.msg('保存成功');
                var index = parent.layer.getFrameIndex(window.name);
                window.parent.loadList(MID);//执行父页面的事件
            })
			Setnum();
        }
        function Edite() {
            var id = getQueryStringRegExp("id");
            //根据ID获取环境监测从表信息
            $.getJSON("/commapiV2", {p_dm: "Hjjc_content_getByID", id: id}, function (data) {
                if (data.success) {
                    $("#jcks").combobox('setValue', data.Table[0].jcks);
                    $("#jyxm").combobox('setValue', data.Table[0].jyxm);
                    $("#jclx").combobox('setValue', data.Table[0].jclx);
                    $("#jcjz").combobox('setText', data.Table[0].jcjz);
                    $("#jcmd").combobox('setValue', data.Table[0].md);
                    $("#bz").textbox('setText', data.Table[0].bz);
                    $("#jcbb").combobox('setValue', data.Table[0].jcbb);
                    $("#xh").numberbox('setValue', data.Table[0].xh);
					
                }
            }, true);
        }
    </script>
</head>
<body>
<div class="layui-form">
    <table class="layui-table " lay-size="sm">
        <tbody>
        <tr>
		<td>序号</td>
            <td>
                <select id="xh" name="xh" class="easyui-numberbox"
                        style="width:170px">
                </select>
            </td>
            <td>检测科室</td>
            <td>
                <select id="jcks" name="jcks" class="easyui-combobox"
                        style="width:170px">
                </select>
            </td>
            <td>监测类型</td>
            <td>
                <select id="jclx" name="jclx" class="easyui-combobox"
                        style="width:170px">
                </select></td>
            
        </tr>

        <tr>
<td>检验项目</td>
            <td>
                <select id="jyxm" name="jyxm" class="easyui-combobox"
                        style="width:170px">
                </select></td>
            <td>监测目的</td>
            <td>
                <select id="jcmd" name="jcmd" class="easyui-combobox"
                        style="width:170px">
                    <option value='常规' selected="selected">常规</option>
                    <option value='流调'>流调</option>
                    <option value='同源性致病菌鉴定'>同源性致病菌鉴定</option>
                </select></td>
            <td>监测标本</td>
            <td>
                <select id="jcbb" name="jcbb" class="easyui-combobox"
                        style="width:170px">
                </select>
            </td>
        </tr>
        <tr>
            <td>需监测菌种</td>
            <td colspan="5"><select id="jcjz" name="jcjz" class="easyui-combobox"
                                    style="width:350px">
            </select></td>
        </tr>
        <tr>
            <td>备注</td>
            <td colspan="5">
                <input id="bz" name="bz" class="easyui-textbox" data-options="multiline:true,readonly:false"
                       style="width:550px;height:50px">
            </td>

        </tr>
        </tbody>
    </table>
</div>
</body>
</html>
